<template>
    <div class="reg-wrap">
        <div class="ms-reg">
            <div class="ms-title">MMC后台管理系统</div>
            <el-form :model="param" :rules="rules" ref="reg" label-width="0px" class="ms-content" status-icon>
                <!-- 用户名 -->
                <el-form-item prop="username">
                    <el-input v-model="param.username" placeholder="username">
                        <el-button slot="prepend" icon="el-icon-lx-people"></el-button>
                    </el-input>
                </el-form-item>
                <!-- 密码 -->
                <el-form-item prop="password">
                    <el-input
                        type="password"
                        placeholder="password"
                        v-model="param.password"
                        @keyup.enter.native="submitForm()"
                    >
                        <el-button slot="prepend" icon="el-icon-lx-lock"></el-button>
                    </el-input>
                </el-form-item>
                <!-- 确认密码 -->
                <el-form-item prop="password1">
                    <el-input
                        type="password"
                        placeholder="checkpassword"
                        v-model="param.password1"
                        @keyup.enter.native="submitForm()"
                    >
                        <el-button slot="prepend" icon="el-icon-lx-lock"></el-button>
                    </el-input>
                </el-form-item>
                <div class="reg-btn">
                    <el-button type="primary" @click="submitForm()">修改密码</el-button>
                </div>
                <p class="reg-tips">Tips : 请牢记您的新密码。</p>
            </el-form>
        </div>
    </div>
</template>

<script>
    import{changepwd} from '../../api/api'
export default {
    data: function() {
        var validatePass = (rule, value, callback) => {
            if (value === '') {
                callback(new Error('请再次输入新密码'));
            } else if (value !== this.param.password) {
                callback(new Error('两次输入密码不一致!'));
            } else {
                callback();
            }
        };
        return {
            param: {
                username: '',
                password: '',
                password1: '',
                token:this.$route.query.token
            },
            rules: {
                username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
                password: [{ required: true, message: '请输入新密码', trigger: 'blur' }],
                password1: [{ required: true, validator: validatePass, trigger: 'blur' }],
            },
        };
    },
    methods: {
        submitForm() {
            var params = {
                username:this.param.username,
                password:this.param.password,
                token:this.param.token,
            }
            changepwd(params).then(res=>{
                    this.$message(res.message);
                    this.$router.push('/login')
            })
        },
    },
};
</script>

<style scoped>
.reg-wrap {
    position: relative;
    width: 100%;
    height: 100%;
    background-image: url(../../assets/img/login-bg2.png);
    background-size: 100%;
}
.ms-title {
    width: 100%;
    line-height: 50px;
    text-align: center;
    font-size: 20px;
    color: #fff;
    border-bottom: 1px solid #ddd;
}
.ms-reg {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 350px;
    margin: -190px 0 0 -175px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.3);
    overflow: hidden;
}
.ms-content {
    padding: 30px 30px;
}
.reg-btn {
    text-align: center;
}
.reg-btn button {
    width: 100%;
    height: 36px;
    margin-bottom: 10px;
    float: left;
    border: 1px;
}
.reg-tips {
    font-size: 12px;
    line-height: 30px;
    color: #fff;
}
</style>